/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"E632F2A0-18A1-464D-9FC7-DAAF66A9799E",variableType:4}
 */
var fConsorcio = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4AD85B8B-2F49-4D86-8E5B-83F948BEBD83",variableType:4}
 */
var fAnio = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0EF0FF3B-D3D6-4C94-AF22-0A5BCC703F29",variableType:4}
 */
var fMes = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"2F4868AF-A272-4549-AA58-A96B626158C3"}
 * @AllowToRunInFind
 */
function buscar(event) {
	controller.find()
	
	mes = fMes
	anio = fAnio
	consorcio_id = fConsorcio
	
	if (controller.search() == 0)
		globals.DIALOGS.showInfoDialog('Aviso','No se encontraron resultados','OK')
	else
		controller.sort('unidad_funcional asc')
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"A0F0391F-5B5D-460C-B21F-E0A77B0B9693"}
 */
function imprimir(event) {
	forms.liquidaciones_impresion.controller.loadRecords(foundset)
	var $file = plugins.file.showFileSaveDialog('c:/Impresiones_Consorcio/'+liquidaciones_to_consorcios.descripcion+'_'+anio+'_'+mes+'.pdf', 'Elija un destino')
	if ($file)
		forms.liquidaciones_impresion.controller.print(false,false,plugins.pdf_output.getPDFPrinter($file.getAbsolutePath()));
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"DFE9DB75-B8C7-49A5-A27C-9102F8F8F281"}
 */
function cargarArchivo(event) {
	var arch = plugins.file.showFileOpenDialog(1, null,  false,  new Array ("TXT,CSV","txt","csv"))
	if (arch != null)
	{
		var error = globals.readFile(arch.getAbsolutePath(),'consorcios','liquidaciones');
		if (error == 1)
			globals.DIALOGS.showErrorDialog('Error','Ocurrio un error','OK')
		else
		{
			globals.DIALOGS.showInfoDialog('Aviso','Proceso terminado con exito','OK')
			databaseManager.saveData()
			databaseManager.refreshRecordFromDatabase(foundset,-1)
		}
	}
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"4F2D94BF-B511-466D-B282-6CDC80CB9B88"}
 */
function vencimientos(event) {
	var $win = application.createWindow('VENCIMIENTOS',JSWindow.MODAL_DIALOG)
	forms.liquidaciones_impresion_1.controller.show($win)
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6EC50C2D-8C24-422A-B6D0-0A4C0582B400"}
 */
function pagar(event) {
	databaseManager.setAutoSave(false)
	var $win = application.createWindow('ALTA_PAGOS',JSWindow.MODAL_DIALOG)
	forms.pago_expensas.controller.newRecord()
	forms.pago_expensas.cod_mov 	= 1
	forms.pago_expensas.unidad_id 	= liquidaciones_to_unidades.unidad_id
	forms.pago_expensas.fecha 		= application.getServerTimeStamp()
	forms.pago_expensas.importe 	= importe_exp_a + importe_exp_b + importe_exp_c
	if (fecha_vencimiento_2 < forms.pago_expensas.fecha)
	{
		forms.pago_expensas.importe = total_vencimiento_2
	}
	else
		if (fecha_vencimiento_1 < forms.pago_expensas.fecha)
		{
			forms.pago_expensas.importe = total_vencimiento_1
		}
	var $mes = fecha_vencimiento_1.getMonth()+1
	forms.pago_expensas.concepto = 'Pago de expensas ' + $mes  + '-' + fecha_vencimiento_1.getFullYear()
	forms.pago_expensas.controller.show($win)
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"61081655-87C7-40EB-B72F-DAB291F831AA"}
 */
function armado(event) {
	forms.liquidaciones_armado.controller.show()
}

/**
 * Called before the form component is rendered.
 *
 * @param {JSRenderEvent} event the render event
 *
 * @properties={typeid:24,uuid:"2720D9EC-7013-4A77-BE7E-9A30F5A519B5"}
 */
function onRenderPagar(event) {
	/** @type {JSRecord<db:/consorcios/liquidaciones>}*/
	var $rcd = event.getRecord()
	if ($rcd.total_pago >= $rcd.expensas_total)
	{
		event.getRenderable().visible = false
	}
}

/**
 * Called before the form component is rendered.
 *
 * @param {JSRenderEvent} event the render event
 *
 * @properties={typeid:24,uuid:"6FF3A8DE-6B35-4852-86D1-398087CB8F7B"}
 */
function onRenderEliminar(event) {
	/** @type {JSRecord<db:/consorcios/liquidaciones>}*/
	var $rcd = event.getRecord()
	if ($rcd.total_pago > 0)
	{
		event.getRenderable().visible = false
	}
}
